package com.chad.library.adapter.base.adapter;

import com.chad.library.R;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.Level0Item;
import com.chad.library.adapter.base.entity.Level1Item;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.List;

/**
 * Created by luoxw on 2016/8/9.
 */
public class QuotePricesoftwareDetailExpandableAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    private static final String TAG = QuotePricesoftwareDetailExpandableAdapter.class.getSimpleName();

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;
    public static final int TYPE_PERSON = 2;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public QuotePricesoftwareDetailExpandableAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_expandable_for_main_module);
        addItemType(TYPE_LEVEL_1, R.layout.item_expandable_special_module);
    }

    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item, int position) {
        switch (helper.getItemViewType()) {
            case TYPE_LEVEL_0:
                final Level0Item lv0 = (Level0Item) item;
                helper.setText(R.id.title, lv0.title)
                        .setText(R.id.sub_title, lv0.subTitle);

//                expand(position);

//                helper.itemView.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        int pos = helper.getAdapterPosition();
//                        Log.d(TAG, "Level 0 item pos: " + pos);
//                        if (lv0.isExpanded()) {
//                            collapse(pos);
//                        } else {
//                            expand(pos);
//                        }
//                    }
//                });
                break;

            case TYPE_LEVEL_1:
                final Level1Item lv1 = (Level1Item) item;
                helper.setText(R.id.title, lv1.title)
                        .setText(R.id.sub_title, lv1.subTitle);
                break;

            case TYPE_PERSON:

                break;
        }
    }
}
